# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : KNN算法实现回归（多维）.py
# @Author: dongguangwen
# @Date  : 2025-01-19 14:13
# 1.导入工具包
from sklearn.neighbors import KNeighborsRegressor

# 2.数据（特征工程）
x = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6]]
y = [0.1, 0.2, 0.3, 0.4, 0.5]

# 3.实力化
model = KNeighborsRegressor(n_neighbors=3)

# 4.训练
model.fit(x, y)

# 5.预测
print(model.predict([[2, 3, 4]]))  # [0.3]
print(model.predict([[5, 6, 7]]))  # [0.4]
